package com.atguigu.tingshu.order.api;

import com.atguigu.tingshu.common.anno.GuiGuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.result.ResultCodeEnum;
import com.atguigu.tingshu.model.order.OrderInfo;
import com.atguigu.tingshu.order.service.OrderInfoService;
import com.atguigu.tingshu.vo.order.OrderInfoVo;
import com.atguigu.tingshu.vo.order.TradeVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Executors;

@Tag(name = "订单管理")
@RestController
@RequestMapping("api/order/orderInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class OrderInfoApiController {

	@Autowired
	private OrderInfoService orderInfoService;

	@GuiGuLogin
	@PostMapping(value = "/trade")
	public Result<OrderInfoVo> trade(@RequestBody TradeVo tradeVo) {
		OrderInfoVo orderInfoVo = orderInfoService.trade(tradeVo) ;
		return Result.build(orderInfoVo , ResultCodeEnum.SUCCESS) ;
	}

	@GuiGuLogin
	@PostMapping(value = "/submitOrder")
	public Result<Map<String , String>> submitOrder(@RequestBody OrderInfoVo orderInfoVo) {
		String orderNo = orderInfoService.submitOrder(orderInfoVo) ;
		Map<String , String> map = new HashMap<>() ;
		map.put("orderNo" , orderNo) ;
		return Result.build(map , ResultCodeEnum.SUCCESS) ;
	}

	@GetMapping(value = "/getOrderInfo/{orderNo}")
	public Result<OrderInfo> getOrderInfo(@PathVariable(value = "orderNo") String orderNo) {
		OrderInfo orderInfo = orderInfoService.getOrderInfoByOrderNo(orderNo);
		return Result.build(orderInfo , ResultCodeEnum.SUCCESS) ;
	}

	@GuiGuLogin
	@GetMapping(value = "/findUserPage/{pageNo}/{pageSize}")
	public Result<IPage<OrderInfo>> findUserPage(@PathVariable(value = "pageNo") Integer pageNo ,@PathVariable(value = "pageSize") Integer pageSize) {
		IPage<OrderInfo> page = orderInfoService.findUserPage(pageNo , pageSize) ;
		return Result.build(page , ResultCodeEnum.SUCCESS) ;
	}
}

